//
//  DepartmentsViewController.m
//  WE
//
//  Created by apple on 15/11/19.
//  Copyright © 2015年 UNOHACHA. All rights reserved.
//

#import "DepartmentsViewController.h"
#import "Size.h"
#import <SDCycleScrollView/SDCycleScrollView.h>
#import "SubjectTableViewCell.h"
#import "DoctorViewController.h"
#import "ToolUtil.h"
@interface DepartmentsViewController ()<UITableViewDelegate,UITableViewDataSource>



@end

@implementation DepartmentsViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, WindowWidth, WindowHeight)];
    [self.view addSubview:self.tableView];
    
    
    NSInteger i = 16;
    self.navigationItem.title = self.string;
    UIScrollView *scrollView = [[UIScrollView alloc] init];
    
    scrollView.frame = CGRectMake(0, 0, WindowWidth, 90*Height);
    self.tableView.tableHeaderView = scrollView;
    
    NSArray * arrWeek=@[@"周六",@"周日",@"周一",@"周二",@"周三",@"周四",@"周五"];
    NSDate *date = [NSDate date];
    NSTimeInterval timeIn = [date timeIntervalSince1970];
    //timeIn = timeIn - 8*3600;
    scrollView.backgroundColor = [UIColor whiteColor];
    scrollView.showsHorizontalScrollIndicator = NO;
    
    scrollView.showsVerticalScrollIndicator = NO;
    scrollView.scrollsToTop = NO;
    //scrollView.isScrollEnabled = YES;
    scrollView.contentSize = CGSizeMake(20*Width*2 + 50*Height*i, 0);
    scrollView.scrollEnabled = YES;
    scrollView.bounces = NO;
    [ToolUtil createLine:89*Height superView:scrollView lift:0 width:20*Width*2 + 50*Height*i hight:1*Height color:[UIColor grayColor]];
    for (int  j = 0; j < i; j++) {
        
        timeIn = timeIn + 24*3600;
        
    NSDate * date1 = [NSDate dateWithTimeIntervalSince1970:timeIn];
        NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSCalendarIdentifierGregorian];
        NSDateComponents *comps = [[NSDateComponents alloc] init] ;
        NSInteger unitFlags =  NSCalendarUnitYear |
        NSCalendarUnitMonth |
        NSCalendarUnitDay |
        NSCalendarUnitWeekday |
        NSCalendarUnitHour |
        NSCalendarUnitMinute |
        NSCalendarUnitSecond;
        comps = [calendar components:unitFlags fromDate:date1];
        NSInteger week = [comps weekday];
        NSInteger month = [comps month];
        NSInteger day = [comps day];
        UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
        button.frame = CGRectMake(20*Width + 50*Height * j , 20*Height, 50*Height, 50*Height);
        button.layer.borderWidth = 0.5;
        button.layer.borderColor = [UIColor grayColor].CGColor;
        UILabel *weekLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 50*Height, 25*Height)];
        weekLabel.text = arrWeek[week-1];
       // weekLabel.text = [NSString stringWithFormat:@"%ld",week];
        weekLabel.font = FONT(14);
        weekLabel.textColor = [UIColor blackColor];
        weekLabel.textAlignment = NSTextAlignmentCenter;
        [button addSubview:weekLabel];
        UILabel *dateLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 25*Height, 50*Height, 25*Height)];
        dateLabel.text = [NSString stringWithFormat:@"%ld-%ld",month,day];
        dateLabel.font = FONT(12);
        dateLabel.textColor = [UIColor blackColor];
        dateLabel.textAlignment = NSTextAlignmentCenter;
        [button addSubview:dateLabel];
        [scrollView addSubview:button];
    }
    self.tableView.showsVerticalScrollIndicator = NO;
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    _tableView.showsVerticalScrollIndicator = NO;

    
}
- (void)viewWillAppear:(BOOL)animated
{
    self.navigationController.navigationBar.hidden = NO;
    
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 10;
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    static NSString *cellId = @"SubjectTableViewCell";
    SubjectTableViewCell *cell = (SubjectTableViewCell*)[tableView dequeueReusableHeaderFooterViewWithIdentifier:cellId];
    if (!cell) {
        cell = [[SubjectTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellId];
        
        
    }
    cell.selectionStyle = UITableViewCellEditingStyleNone;
       NSString * text = @"★10.0";
   // cell.levelLabel.at = [UIColor orangeColor];
    
    NSMutableAttributedString *str = [[NSMutableAttributedString alloc] initWithString:text];
    NSInteger i = text.length;
    [str addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:12] range:NSMakeRange(0, i-2)];
    [str addAttribute:NSForegroundColorAttributeName value:[UIColor orangeColor] range:NSMakeRange(0, i)];
    
    [str addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:10] range:NSMakeRange(i-1, 1)];
    
    
    cell.levelLabel.attributedText = str;
    cell.nameLabel.text = @"李民选";
    cell.imageV.image = [UIImage imageNamed:@"111"];
    cell.numberLabel.text = @"接诊量 100";
    cell.specialityLabel.text = @"牙周炎,牙龈炎,智齿冠周炎,牙髓炎,牙髓病,口腔溃疡";
    return cell;
}


- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 100*Height;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    DoctorViewController *doctorVC = [[DoctorViewController alloc] init];
    
    [self.navigationController pushViewController:doctorVC animated:YES];
    
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
